package pogvue.io;

import pogvue.datamodel.*;

import java.util.*;
import java.io.*;

public class FormatAdapter {
 
  public static String get(String format,Vector seqs) {
    SequenceI [] s = new SequenceI[seqs.size()];
    for (int i=0;i<seqs.size(); i++) {
      s[i] = (SequenceI)seqs.elementAt(i);
    }
    if (FormatProperties.contains(format)) {
      AlignFile afile = FormatFactory.get(format,s);
      System.out.println("Afile " + afile);

      return afile.print();
    } else {
      // Should throw exception here
      return null;
    }
  }

  public static String get(String format,SequenceI[] s) {
    if (FormatProperties.contains(format)) {
      AlignFile afile = FormatFactory.get(format,s);
      return afile.print();
    } else {
      // Should throw exception here
      return null;
    }
  }

  public static SequenceI[] read(String format,String inStr) {
    if (FormatProperties.contains(format)) {
      AlignFile afile = FormatFactory.get(format,inStr);
      return afile.getSeqsAsArray();
    } else {
    // Should throw exception
      return null;
    }
  }

  public static SequenceI[] read(String inFile, String type, String format) {
    System.out.println("In FormatAdapter: " + inFile + " " + type + " " + format);
    if (FormatProperties.contains(format)) {
      try {
        AlignFile afile = FormatFactory.get(format,inFile,type);
        System.out.println("AF " + afile);
        return afile.getSeqsAsArray();
      } catch (Exception e) {
	System.out.println("Exception " + e + " in FormatAdapter");
      }
    } else {
      // Should throw exception
      return null;
    }
    return null;
  }


  public static void main(String[] args) {
    SequenceI[] s  = FormatAdapter.read(args[0],"File",args[1]);

    System.out.println(FormatAdapter.get(args[2],s));
  }
}
